package com.cheng.web.action.transit;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.ParentPackage;
import org.apache.struts2.convention.annotation.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Controller;

import com.cheng.bos.actionUtils.ActionUtils;
import com.cheng.domain.transit.TransitInfo;
import com.cheng.service.transit.TransitinfoService;
import com.opensymphony.xwork2.ActionContext;

@ParentPackage("json-default")
@Namespace("/transitinfo")
@Controller
@Scope("prototype")
public class TransitinfoAction extends ActionUtils<TransitInfo> {

	@Autowired
	private TransitinfoService transitinfoService;
	
	//属性驱动获取运单id
	private String wayBillIds;
	
	public void setWayBillIds(String wayBillIds) {
		this.wayBillIds = wayBillIds;
	}

	@Action(value="transitinfo_creat",results={@Result(name="success",type="json")})
	public String creatTransitInfo(){
		Map<String, Object> result= new HashMap<>();
		try {
			transitinfoService.creatTransitInfo(wayBillIds);
			result.put("title", "操作成功");
			result.put("msg", "运单开启中转运送操作成功");
		} catch (Exception e) {
			result.put("title", "操作失败");
			result.put("msg", "运单开启中转运送操作失败,失败原因："+e.getMessage());
		}
		ActionContext.getContext().getValueStack().push(result);
		return SUCCESS;
	}
	
	@Action(value="transitinfo_query",results={@Result(name="success",type="json")})
	public String findTransitInfo(){
		Pageable pageable = new PageRequest(page-1, rows);
		Page<TransitInfo> list = transitinfoService.findAll(pageable);
		pushPageDataToValueStack(list);
		return SUCCESS;
	}
}
